﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;

namespace UIDocument.UserControl
    {
    public partial class ucFileUpload : System.Web.UI.UserControl
        {
        string filestatus;
        protected void Page_Load(object sender, EventArgs e)
            {

            }

        protected void btnFileUpload_Click(object sender, System.EventArgs e)
            {
                if (Request.Files["uploadFile"] == null)
                    {
                    throw new Exception();
                    }
                string fileName = Request.Files["uploadFile"].FileName;
                if (fileName.Length > 0)
                    {
                    switch (Path.GetExtension(fileName))
                        {
                        case ".jpg":
                            Request.Files["uploadFile"].SaveAs(System.Web.Hosting.HostingEnvironment.MapPath("~/Image/" + fileName));
                            filestatus = "File Upload Successfully...";
                            break;
                        case ".jpeg":
                            Request.Files["uploadFile"].SaveAs(System.Web.Hosting.HostingEnvironment.MapPath("~/Image/" + fileName));
                            filestatus = "File Upload Successfully...";
                            break;
                        case ".excel":
                            Request.Files["uploadFile"].SaveAs(System.Web.Hosting.HostingEnvironment.MapPath("~/DocumentFile/Excel/" + fileName));
                            filestatus = "File Upload Successfully...";
                            break;
                        case ".pdf":
                            Request.Files["uploadFile"].SaveAs(System.Web.Hosting.HostingEnvironment.MapPath("~/DocumentFile/PdfFile/" + fileName));
                            filestatus = "File Upload Successfully...";
                            break;
                        case ".doc":
                            Request.Files["uploadFile"].SaveAs(System.Web.Hosting.HostingEnvironment.MapPath("~/DocumentFile/WordFile/" + fileName));
                            filestatus = "File Upload Successfully...";
                            break;
                        default:
                            filestatus = "Invalid Extenction File !!!";
                            break;
                        }
                    StringBuilder str = new StringBuilder();
                    str.Append( "<script type ="+"text/javascript"+">alert('");
                    str.Append(filestatus);
                    str.Append( "');</script>");
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "ALERT", str.ToString());
                    }
                }
            }

    
    public enum FileExtenction
        {
        jpeg,
        jpg,
        excel,
        pdf,
        doc
        }
    }
